<script setup>
  import {ref} from "vue";

  const userArr=ref([])

  const user=ref({
    uname:'',
    salary:'',
    job:''
  })

  const btn=()=>{

    if(user.value.uname.trim()==null || user.value.salary.trim()==null || user.value.job.trim()==null){
      alert('请输入完整信息')
      return;
    }
    userArr.value.push(user.value)
    user.value={
      uname:'',
      salary:'',
      job:''
    }
  }
</script>

<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="user.uname">
  <input type="text" placeholder="请输入员工工资" v-model="user.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="user.job">
  <button @click="btn">点我添加</button>
  <hr>
  <table border="1">
    <tr>
      <th>员工编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(item,index) in userArr">
      <td>{{index+1}}</td>
      <td>{{item.uname}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>
  </table>
</template>

<style scoped>

</style>